using System;
using System.Collections.Generic;
using System.Linq;
namespace TTSoft.MyApp.Repositories
{
	#region using
	using TTSoft.MyApp.Models;
	#endregion
	public class TacGiaRepository
	{
		public static List<TacGia> SelectAll()
		{
			return DataContext.Instance.TacGia.ToList();
		}

		public static TacGia SelectByID(int idtacgia)
		{
			return DataContext.Instance.TacGia.FirstOrDefault(item => item.IDTacGia == idtacgia );
		}

		public static bool Insert(TacGia obj)
		{
			try
			{
				DataContext.Instance.TacGia.AddObject(obj);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Delete(int idtacgia)
		{
			try
			{
				var delitem = DataContext.Instance.TacGia.FirstOrDefault(item => item.IDTacGia == idtacgia );
				DataContext.Instance.TacGia.DeleteObject(delitem);
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static bool Save()
		{
			try
			{
				DataContext.Instance.SaveChanges();
				return true;
			}
			catch
			{
				return false;
			}
		}

		public static List<TacGia> RetrieveByID(int idtacgia)
		{
			return (from item in DataContext.Instance.TacGia where  item.IDTacGia == idtacgia  select item).ToList();
		}

	}
}